package com.studentstreet.tools.dbhelper;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {
	public final static int DATABASE_VERSION = 1;
	public final static String DATABASE_NAME = "shop.db";

	public DBHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(DBTools.getSellerSQL());
		db.execSQL(DBTools.getGoodsSQL());
		db.execSQL(DBTools.getCommentSQL());
		db.execSQL(DBTools.getOrderItemSQL());
		db.execSQL(DBTools.getOrderSQL());
		db.execSQL(DBTools.getUserSQL());
		db.execSQL(DBTools.getStoreSQL());
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS " + DBTools.TABLE_SELLER);
		db.execSQL("DROP TABLE IF EXISTS " + DBTools.TABLE_GOODS);
		db.execSQL("DROP TABLE IF EXISTS " + DBTools.TABLE_COMMENT);
		db.execSQL("DROP TABLE IF EXISTS " + DBTools.TABLE_ORDER_ITEM);
		db.execSQL("DROP TABLE IF EXISTS " + DBTools.TABLE_ORDER);
		db.execSQL("DROP TABLE IF EXISTS " + DBTools.TABLE_USER);
		db.execSQL("DROP TABLE IF EXISTS " + DBTools.TABLE_STORE);

		onCreate(db);

	}

}
